import { shallowRef } from 'vue'

import { catchFn } from '@/libs/common'
import { getGroupList } from './api'

const list = shallowRef<T_GroupInfo[]>([])

export { list }

/**
 * 更新群信息
 */
const update = () =>
  catchFn(async () => {
    const { data } = await getGroupList()

    list.value = data
  })

/**
 * 还原状态
 */
const clear = () => (list.value = [])

export { update, clear }
